package com.yanqu.road.dao.impl.config;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.config.goods.MammonConfig;
import com.yanqu.road.utils.property.PropertyHelper;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class MammonConfigDaoImpl extends TempDao {

    public Map<Integer, MammonConfig> getMammonConfigMap() {
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, MammonConfig> dataMap = new ConcurrentHashMap<>();
        String sql = "select * from t_p_mammon";
        try {
            getDb().setConnName(DbNameStrategy.getConfigDb());
            call = getDb().getConnection().prepareCall(sql);
            rs = call.executeQuery();
            while (rs.next()) {
                MammonConfig data = new MammonConfig();
                data.setMammonDecorationId(rs.getInt("needTitle"));
                data.setType(rs.getInt("type"));
                data.setChildType(rs.getInt("littleType"));
                data.setCongratulateRewardStr(rs.getString("congratulateReward"));
                data.setCongratulateReward(PropertyHelper.parseStringToProperty(data.getCongratulateRewardStr()));
                dataMap.put(data.getMammonDecorationId(), data);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }
}
